package org.lilred.nzbberry.ui;

import org.lilred.nzbberry.config.Resizer;
import org.lilred.nzbberry.util.ScaleImage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class IndicatorField extends Field {
	private int indicatorColor = 0xFFFF00;
	private Bitmap indicatorBitmap;
	
	public IndicatorField() {
		EncodedImage e = EncodedImage.getEncodedImageResource("indicator.png");
		e = ScaleImage.toWidth(e, Resizer.resize(16));
		indicatorBitmap = e.getBitmap();
	}
	
	public void setColor(int color) {
		indicatorColor = color;
		invalidate();
	}
	
	public int getColor() {
		return indicatorColor;
	}
	
	protected void layout(int width, int height) {
		setExtent(indicatorBitmap.getWidth(), indicatorBitmap.getHeight());
	}
	
	public int getPreferredHeight() {
		return indicatorBitmap.getHeight();
	}
	
	public int getPreferredWidth() {
		return indicatorBitmap.getWidth();
	}

	protected void paint(Graphics g) {
		//Draw the status indicator(s)
		g.setColor(indicatorColor);
		g.fillArc(0, 0, indicatorBitmap.getWidth(), indicatorBitmap.getHeight(), 0, 360);

		g.drawBitmap(0, //X pos
				0, //Y pos 
				indicatorBitmap.getWidth(), //Width
				indicatorBitmap.getHeight(), //Height
				indicatorBitmap, 0, 0);
	}

}
